import 'package:flutter/cupertino.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

///刷新组件
class RefreshWidget extends StatelessWidget {
  final bool? enablePullDown; //下拉刷新是否开启
  final bool? enablePullUp; //上拉加载更多
  final Widget? header; //头布局
  final Widget? footer; //尾布局
  final VoidCallback? onRefresh; //下拉刷新回调
  final VoidCallback? onLoading; //上拉加载回调
  final RefreshController controller; //刷新控制器
  final Widget child; //子布局

  const RefreshWidget(
      {super.key,
      this.enablePullDown,
      this.enablePullUp,
      this.header,
      this.footer,
      required this.onRefresh,
      required this.onLoading,
      required this.controller,
      required this.child});

  Widget _refreshWidget() {
    return SmartRefresher(
        enablePullDown: true,
        enablePullUp: true,
        controller: controller,
        header: header ?? const ClassicHeader(),
        footer: footer ?? const ClassicFooter(),
        onRefresh: onRefresh,
        onLoading: onLoading,
        child: child);
  }

  @override
  Widget build(BuildContext context) {
    return _refreshWidget();
  }
}
